<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='https://cdn.staticfile.org/react/16.4.0/umd/react.development.js'></script>
    <script src='https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js'></script>
    <!-- 生产环境中不建议使用 -->
    <script src='https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js'></script>
    <!-- PropTypes文件 -->
    <script src='https://unpkg.com/prop-types@15.6.2/prop-types.js'></script>
</head>

<body>
    <div id='app'>
    </div>
    <script type='text/babel'>
        class Demo extends React.Component{
            showData1 = ()=>{
                console.log(this.input1.value)
            }

            showData2 = ()=>{
                console.log(this.input2.value)
            }

            saveInput = (node)=>{
                this.input1 = node
            }

            render(){
                return (
                    <div>
                        {/*
                            注意，如果你把ref写成了内联的回调函数形式，那么这个回调函数会在页面更新的时候执行两次，一次传入null用来清空，一次传入真实的节点。如果要规避这个问题，可以把回调函数写在类里，就像下面这个input2一样。不过这个问题没啥影响，可以忽略不计，只是较真的时候可以当做一个问题来看。日后的代码写成内联就好
                        */}
                        <input type="text" ref={this.saveInput} onBlur={this.showData1}/>
                        <input type="text" ref={node=>this.input2 = node} onBlur={this.showData2}/>    
                    </div>
                )
            }
        }

        ReactDOM.render(<Demo/>,document.getElementById('app'))
    </script>
</body>

</html>